import { createRouter, createWebHistory } from 'vue-router'
// import { routerGuard } from '@/utils/routerGuard' // 导入守卫

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/login'
    },
    {
      path: '/login',
      name: 'Login',
      component: () => import('../views/login/Login.vue'),
      meta: { title: '登录', requiresAuth: false }
    },
    {
      path: '/register',
      name: 'Register',
      component: () => import('../views/login/Register.vue'),
      meta: { title: '注册', requiresAuth: false }
    },
    // 超级管理员路由
    {
      path: '/super-admin',
      name: 'SuperAdminLayout',
      component: () => import('../components/layout/MainLayout.vue'),
      meta: { title: '超级管理员后台', requiresAuth: true, role: 'super_admin' },
      children: [
        {
          path: 'user-manage',
          name: 'UserManage',
          component: () => import('../views/super-admin/UserManage.vue'),
          meta: { title: '用户管理', role: 'super_admin' }
        },
        {
          path: 'product-manage',
          name: 'SuperProductManage',
          component: () => import('../views/super-admin/ProductManage.vue'),
          meta: { title: '商品管理', role: 'super_admin' }
        },
        {
          path: 'hospital-manage',
          name: 'HospitalManage',
          component: () => import('../views/super-admin/HospitalManage.vue'),
          meta: { title: '医院管理', role: 'super_admin' }
        },
        {
          path: 'doctor-manage',
          name: 'DoctorManage',
          component: () => import('../views/super-admin/DoctorManage.vue'),
          meta: { title: '医生管理', role: 'super_admin' }
        },
        {
          path: 'menu-manage',
          name: 'MenuManage',
          component: () => import('../views/super-admin/MenuManage.vue'),
          meta: { title: '菜单管理', role: 'super_admin' }
        },
        {
          path: 'merchant-manage',
          name: 'MerchantManage',
          component: () => import('../views/super-admin/MerchantManage.vue'),
          meta: { title: '商家管理', role: 'super_admin' }
        },
         {
          path: 'post-manage',
          name: 'PostManage',
          component: () => import('../views/super-admin/PostManage.vue'),
          meta: { title: '帖子管理', role: 'super_admin' }
        },
         {
          path: 'notice-manage',
          name: 'NoticeManage',
          component: () => import('../views/super-admin/NoticeManage.vue'),
          meta: { title: '公告管理', role: 'super_admin' }
        }
      ]
    },
    // 商家路由
    {
      path: '/merchant',
      name: 'MerchantLayout',
      component: () => import('../components/layout/MainLayout.vue'),
      meta: { title: '商家后台', requiresAuth: true, role: 'merchant' },
      children: [
        {
          path: 'product-manage',
          name: 'MerchantProductManage',
          component: () => import('../views/merchant/ProductManage.vue'),
          meta: { title: '商品管理', role: 'merchant' }
        },
        {
          path: 'merchant-info',
          name: 'MerchantInfo',
          component: () => import('../views/merchant/MerchantInfo.vue'),
          meta: { title: '商家信息管理', role: 'merchant' }
        },
        {
          path: 'order-manage',
          name: 'OrderManage',
          component: () => import('../views/merchant/OrderManage.vue'),
          meta: { title: '订单管理', role: 'merchant' }
        }
      ]
    },
    // 医生路由
    {
      path: '/doctor',
      name: 'DoctorLayout',
      component: () => import('../components/layout/MainLayout.vue'),
      meta: { title: '医生后台', requiresAuth: true, role: 'doctor' },
      children: [
        {
          path: 'doctor-info',
          name: 'DoctorInfo',
          component: () => import('../views/doctor/DoctorInfo.vue'),
          meta: { title: '医生信息管理', role: 'doctor' }
        },
        {
          path: 'treatment-record',
          name: 'TreatmentRecord',
          component: () => import('../views/doctor/TreatmentRecord.vue'),
          meta: { title: '诊疗记录管理', role: 'doctor' }
        },
        {
          path: 'appointment-manage',
          name: 'AppointmentManage',
          component: () => import('../views/doctor/AppointmentManage.vue'),
          meta: { title: '预约管理', role: 'doctor' }
        }
      ]
    },
  ]
})

// 👉 关键修改：调用守卫时传入 router 参数
// routerGuard(router)

export default router